API - Send Your First OTP Call
Imagine this: You're building a secure and user-friendly application. You want to ensure your users can authenticate quickly and reliably, no matter where they are. The Betatel OTP Call API is here to help you make that happen! Follow these simple steps to integrate and send your first OTP call.
Step 1: Understand the Basics
The OTP Call API allows you to initiate an automated voice call that delivers a One-Time Password (OTP) message. This ensures secure communication between your application and the recipient.
OTP Call - Endpoint
https://api.betatel.com/api/v1/callgen/call/otp
- Method:
POST
Headers
Before you can make a request, your API call needs some essential details in the headers:
Param | Value | Description |
---|---|---|
Content-type | application/json | Specifies the payload format. |
x-api-key | {{x-api-key} | API key for authorization. |
Step 2: Build the Request
Now it’s time to prepare the payload for your request. This is like writing the script for the call. Here are the key parameters:
Parameter | Type | Required | Description |
---|---|---|---|
callee | string | Yes | The phone number of the recipient (in international format). |
caller | string | Yes | The phone number initiating the call (in international format). |
testCall | boolean | No | Indicates if the call is for testing purposes. |
text | string | Yes | The OTP message to be delivered to the recipient. |
language | string | Yes | The language code for the message (e.g., en for English, zh for Chinese). |
maxRingTime | integer | No | Maximum duration (in seconds) for ringing before the call is terminated. |
maxBillTime | integer | No | Maximum billable duration (in seconds) for the call. |
Here’s an example of a request body:
{
"callee": "351913510668",
"caller": "381658345434",
"testCall":false,
"text":"Your auhtorization code is 345434",
"language":"zh",
"maxRingTime": 10,
"maxBillTime": 20
}
Test Before Going Live
Use the testCall parameter set to true to simulate the OTP call without actually delivering it. This ensures your integration is working as expected before live deployment.
Step 3: Make the Call
Now you’re ready to send your first OTP call! Choose your favorite programming language and use the following snippets to make the request.
- cUrl
- Python
- Node.js
- PHP
- Java
- C#
curl --location 'https://dev.api.betatel.com/api/v1/callgen/call/otp' \
--header 'x-api-key: Ng84v5PVF-NXcP9xPZAj8_9G8jtFQ5z9FVJd_cXlKzc' \
--header 'Content-Type: application/json' \
--data '{
"callee": "351913510668",
"caller": "381658345434",
"testCall":false,
"text":"Your auhtorization code is 345434",
"language":"zh",
"maxRingTime": 10,
"maxBillTime": 20
}'
import http.client
import json
conn = http.client.HTTPSConnection("dev.api.betatel.com")
payload = json.dumps({
"callee": "351913510668",
"caller": "381658345434",
"testCall": False,
"text": "Your auhtorization code is 345434",
"language": "zh",
"maxRingTime": 10,
"maxBillTime": 20
})
headers = {
'x-api-key': 'Ng84v5PVF-NXcP9xPZAj8_9G8jtFQ5z9FVJd_cXlKzc',
'Content-Type': 'application/json'
}
conn.request("POST", "/api/v1/callgen/call/otp", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
const axios = require('axios');
let data = JSON.stringify({
"callee": "351913510668",
"caller": "381658345434",
"testCall": false,
"text": "Your auhtorization code is 345434",
"language": "zh",
"maxRingTime": 10,
"maxBillTime": 20
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://dev.api.betatel.com/api/v1/callgen/call/otp',
headers: {
'x-api-key': 'Ng84v5PVF-NXcP9xPZAj8_9G8jtFQ5z9FVJd_cXlKzc',
'Content-Type': 'application/json'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://dev.api.betatel.com/api/v1/callgen/call/otp',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"callee": "351913510668",
"caller": "381658345434",
"testCall":false,
"text":"Your auhtorization code is 345434",
"language":"zh",
"maxRingTime": 10,
"maxBillTime": 20
}',
CURLOPT_HTTPHEADER => array(
'x-api-key: Ng84v5PVF-NXcP9xPZAj8_9G8jtFQ5z9FVJd_cXlKzc',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://dev.api.betatel.com/api/v1/callgen/call/otp")
.header("x-api-key", "Ng84v5PVF-NXcP9xPZAj8_9G8jtFQ5z9FVJd_cXlKzc")
.header("Content-Type", "application/json")
.body("{\n \"callee\": \"351913510668\",\n \"caller\": \"381658345434\",\n \"testCall\":false,\n \"text\":\"Your auhtorization code is 345434\",\n \"language\":\"zh\",\n \"maxRingTime\": 10,\n \"maxBillTime\": 20\n}")
.asString();
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://dev.api.betatel.com/api/v1/callgen/call/otp");
request.Headers.Add("x-api-key", "Ng84v5PVF-NXcP9xPZAj8_9G8jtFQ5z9FVJd_cXlKzc");
var content = new StringContent("{\n \"callee\": \"351913510668\",\n \"caller\": \"381658345434\",\n \"testCall\":false,\n \"text\":\"Your auhtorization code is 345434\",\n \"language\":\"zh\",\n \"maxRingTime\": 10,\n \"maxBillTime\": 20\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
Step 4: Check the Response
After making the call, the API will respond with a unique identifier (uuid) for your OTP call. Here’s what a successful response looks like:
-
Status Code:
200 OK
-
Content-Type:
application/json
JSON Schema:
{
"uuid": "string"
}
Response Tracking
The uuid in the response acts as a unique identifier for the OTP call. Use it to track the status of the call or troubleshoot issues if necessary.
What’s Next?
🎉 Congratulations! You’ve successfully sent your first OTP call. Now, you can:
- Integrate the API into your application workflows.
- Customize the text, language, and timing to suit your users’ needs.
- Explore other advanced features in the Betatel API documentation.
Your application is now one step closer to providing secure, reliable authentication with Betatel's OTP Call API. 🚀